package com.insurance.service.impl;

import com.insurance.dao.AuthenticationUserDao;
import com.insurance.entity.AuthenticationUserEntity;
import com.insurance.service.AuthenticationUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.Query;

@Service("authenticationUserService")
public class AuthenticationUserServiceImpl extends ServiceImpl<AuthenticationUserDao, AuthenticationUserEntity> implements AuthenticationUserService {

    @Autowired
    private AuthenticationUserDao authenticationUserDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AuthenticationUserEntity> page = this.page(
                new Query<AuthenticationUserEntity>().getPage(params),
                new QueryWrapper<AuthenticationUserEntity>()
        );

        return new PageUtils(page);
    }

    //region 通过用户名查询用户

    /**
     * 通过用户名查询用户
     *
     * @param userName 用户名
     * @return
     */
    @Override
    public AuthenticationUserEntity findByUserName(String userName){
        if (StringUtils.isBlank(userName)) {
            return null;
        }
        QueryWrapper<AuthenticationUserEntity> queryWrapper = new QueryWrapper<AuthenticationUserEntity>();
        queryWrapper.eq("user_name", userName);
        AuthenticationUserEntity authenticationUserEntity = authenticationUserDao.selectOne(queryWrapper);
        return authenticationUserEntity;
    }
    //endregion

}